package com.yoyo.itravel.dao;

import com.yoyo.itravel.bean.Sight;
import com.yoyo.itravel.bean.TicketTypeDetail;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;

/**
 * @Description 门票具体类型持久层接口
 * @Author HZX
 * @Version 1.0
 * @Date 2020/6/26 11:32
 */
@Repository
public interface ITicketTypeDetailDao {

    /**
     * @Description 添加门票具体类型
     *
     * @param ticketTypeDetail
     * @return int
     */

    @Insert("insert into tb_ticket_detail_type(detailTypeId,ticketTypeId,detailTypeName,orderPrice,initPrice,isOrder,isCancel," +
            " cancelRule, isInstantConfirm, startOrderDate, description, enOrderDays, maxOrderNum, initStockNum, recordTime) " +
            "values(#{detailTypeId},#{ticketTypeId},#{detailTypeName},#{orderPrice}," +
            "#{initPrice},#{isOrder},#{isCancel},#{cancelRule},#{isInstantConfirm}," +
            "#{startOrderDate},#{description},#{enOrderDays},#{maxOrderNum}," +
            "#{initStockNum},#{recordTime})")
    int insert(TicketTypeDetail ticketTypeDetail) throws SQLException;

    /**
     * @Description 查找所有的景点门票具体类型
     *
     * @param
     * @return java.util.List<cn.hut.travel.bean.TicketTypeDetail>
     */
    @Select("select * from tb_ticket_detail_type")
    List<TicketTypeDetail> selectAll() throws SQLException;

    /**
     * @Description 通过景点门票类型id查找该类型下的所有门票具体类型数据
     *
     * @param ticketTypeId
     * @return java.util.List<cn.hut.travel.bean.TicketTypeDetail>
     */
    @Select("select * from tb_ticket_detail_type where ticketTypeId=#{ticketTypeId}")
    List<TicketTypeDetail> selectByTicketTypeId(String ticketTypeId) throws SQLException;

    /**
     * @Description 通过门票类型id查找该类型下的景点门票具体类型的最低价
     *
     * @param ticketTypeId
     * @return java.math.BigDecimal
     */
    @Select("select MIN(orderPrice) from tb_ticket_detail_type where ticketTypeId=#{ticketTypeId}")
    BigDecimal selectLowestPriceByTicketTypeId(String ticketTypeId) throws SQLException;

    /**
     * @Description 通过具体门票类型id获得具体门票类型对象
     *
     * @param detailTypeId
     * @return cn.hut.travel.bean.TicketTypeDetail
     */
    @Select("select * from tb_ticket_detail_type where detailTypeId=#{detailTypeId}")
    TicketTypeDetail selectByTicketDetailTypeId(String detailTypeId) throws SQLException;

    /**
     * @Description 通过门票具体类型id查找对应的景点对象
     *
     * @param detailTypeId
     * @return cn.hut.travel.bean.Sight
     */
    @Select("SELECT * FROM tb_sight s WHERE sightId IN (SELECT sightId FROM tb_ticket_type t WHERE ticketTypeId IN (SELECT ticketTypeId FROM tb_ticket_detail_type WHERE detailTypeId=#{detailTypeId}))")
    Sight selectSightByDetailTypeId(String detailTypeId) throws SQLException;
}
